package com.lagou.bean;

import com.lagou.service.WorkService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Component;

import java.util.Objects;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;

@Component
public class ConsumerComponent implements Runnable{

    public ConsumerComponent(WorkService workService){
        this.workService = workService;
    }

    private WorkService workService;

    public void go(){

        String result = null;
        final int i = ThreadLocalRandom.current().nextInt(3);
        switch (i) {
            case 0:
                result = workService.methodA("a");
                break;
            case 1:
                result = workService.methodB("b");
                break;
            case 2:
                result = workService.methodC("c");
                break;
            default:
                break;
        }
        System.out.println(Thread.currentThread().getName() + " result = " + Objects.toString(result, ""));

    }

    @Override
    public void run() {
        go();
    }
}
